import { useRouter } from 'vue-router';
import { PageEnum } from '../../enums/pageEnum';
import { h } from 'vue';
import IndexIcon from '@/assets/images/index/菜单-首页.png';
import ProdIcon from '@/assets/images/index/菜单-产品.png';
import AnswerIcon from '@/assets/images/index/菜单-方案.png';
import PriceIcon from '@/assets/images/index/菜单-价格.png';
import RegIcon from '@/assets/images/index/菜单-登录.png';
import ProviderIcon from '@/assets/images/index/case_icon.png';
import CaseIcon from '@/assets/images/index/provider_icon.png';
import { getBoothUrl } from '@/api/service/publicity';
import { useDetector } from '@/utils/index';



const renderIcon = (iconPath: string) => {
  return () => {
    return h('img', { src: iconPath, style: `width:16px;` });
  };
};
export const options = [
  {
    label: '活动报名',
    key: 1,
  },
  // {
  //   label: '兼职管理',
  //   key: 3,
  // },
  {
    label: '展商管理',
    key: 6,
  },
  {
    label: '会展CRM',
    key: 7,
  },
  // {
  //   label: '数字平台',
  //   key: 5,
  // },
  {
    label: '动态展位图',
    key: 'booth',
  },
];
export const optSolutions = [
  { label: '数智现场', key: 8 },
  { label: '数字营销', key: 9 },
  { label: '商旅服务', key: 'slfw' },
];

export const h5Options = [
  {
    label: '首页',
    key: 'Home',
    icon: renderIcon(IndexIcon),
  },
  {
    label: '产品及服务',
    key: 'ProductAndServer',
    children: options,
    icon: renderIcon(ProdIcon),
  },
  {
    label: '解决方案',
    key: 'Answer',
    children: optSolutions,
    icon: renderIcon(AnswerIcon),
  },
  {
    label: '价格',
    key: 'Price',
    icon: renderIcon(PriceIcon),
  },
  {
    label: '案例',
    key: 'Case',
    icon: renderIcon(CaseIcon),
  },
  {
    label: '服务商',
    key: 'ServiceProvider',
    icon: renderIcon(ProviderIcon),
  },
  {
    label: '登录/注册',
    key: 'Login',
    icon: renderIcon(RegIcon),
  },
];

export function useMenuLink() {
  const router = useRouter();
  function toHome() {
    router.push(PageEnum.BASE_HOME);
  }
  function handleRelease() {
    window.open(import.meta.env.VITE_GLOB_SPONSOR_URL + '/cdmp/register');
  }
  function toSponsor() {
    window.open(import.meta.env.VITE_GLOB_SPONSOR_URL + '/cdmp/');
  }

  function toNext(url) {
    router.push(url);
  }

  function toBooth() {
    getBoothUrl().then(async (res:any) => {
      const detector = await useDetector();
      if (detector?.mobile) {
        window.location.href = res.url;
      } else {
        window.open(res.url, '_blank');
      }
    });
  }
  function toPage() {
    const url = 'https://zbase.huoyan.cn/shang-lu-fu-wu-';
    window.open(url, '_blank');
  }

  function handleSelect(key) {
    switch (key) {
      case 1:
        router.push({ name: 'signin' });
        break;
      case 2:
        router.push({ name: 'exhibitorSystem' });
        break;
      // case 3:
      //   router.push({ name: 'parttime' });
      //   break;
      case 4:
        router.push({ name: 'marketing' });
        break;
      // case 5:
      //   router.push({ name: 'platform' });
      //   break;
      case 6:
        router.push({ name: 'exhibitor' });
        break;
      case 7:
        router.push({ name: 'crm' });
        break;
      case 8:
        router.push('/onsite');
        break;
      case 9:
        router.push('/marketing');
        break;
      case 'Home':
        router.push('/');
        break;
      case 'Price':
        router.push('/price');
        break;
      case 'Case':
        router.push('/case');
        break;
      case 'ServiceProvider':
        router.push('/service');
        break;
      case 'Login':
        toSponsor();
        break;
      case 'booth':
        toBooth();
        break;
      case 'slfw':
        toPage();
        break;
    }
  }
  
  return {
    toHome,
    handleSelect,
    toNext,
    handleRelease,
    toSponsor,
    toPage,
   
  };
}
